package swu.edu.cn.javaee.controller;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import swu.edu.cn.javaee.entity.TcommentInfo;
import swu.edu.cn.javaee.service.TcommentService;
import static swu.edu.cn.javaee.component.Signal.*;

@Controller
//解决跨域问题：允许所有源域名访问
@CrossOrigin(origins = "*")

public class TcommentController {
    @Resource
    private TcommentService tcommentService;

    //新增评论
    @RequestMapping("/saveTcomment")
    @ResponseBody
    public String saveTcomment(String comment,String uid,String tid,String parent_id){
        String result=tcommentService.saveTcomment(comment,uid,tid,parent_id);
        if (result==SUCCESS_CODE){
            return result;
        }
        else {
            return FAILED_CODE_COMMENT;
        }
    }

    //展示帖子下所有评论
    @RequestMapping("/queryTcommentList")
    @ResponseBody
    public TcommentInfo queryTcommentList(String tid){
        TcommentInfo tcommentInfo=tcommentService.queryTcommentList(tid);
        if (tcommentInfo!=null){
            return tcommentInfo;
        }
        else {
            return null;
        }
    }

    //删除评论
    @RequestMapping("/deleteTcomment")
    @ResponseBody
    public String deleteTcomment(String tm_id){
        String result=tcommentService.deleteTcomment(tm_id);
        return result;
    }

}
